﻿
Imports std

Public Class slice_wrapper
    Implements islice

    Protected ReadOnly slice As islice = Nothing

    Protected Sub New(ByVal s As islice)
        assert(Not s Is Nothing)
        Me.slice = s
    End Sub

    Protected Overridable Function workon(ByVal d As _do(Of eventComb)) As eventComb
        assert(Not d Is Nothing)
        Return d()
    End Function

    Public Overridable Function capacity(ByVal result As pointer(Of Int64)) As eventComb _
                                        Implements islice.capacity
        Return workon(Function() slice.capacity(result))
    End Function

    Public Overridable Function delete(ByVal key As String,
                                       ByVal result As pointer(Of Boolean)) As eventComb _
                                      Implements islice.delete
        Return workon(Function() slice.delete(key, result))
    End Function

    Public Overridable Function empty(ByVal result As pointer(Of Boolean)) As eventComb _
                                     Implements islice.empty
        Return workon(Function() slice.empty(result))
    End Function

    Public Overridable Function full(ByVal result As pointer(Of Boolean)) As eventComb _
                                    Implements islice.full
        Return workon(Function() slice.full(result))
    End Function

    Public Overridable Function heartbeat(ByVal result As pointer(Of Boolean)) As eventComb _
                                         Implements islice.heartbeat
        Return workon(Function() slice.heartbeat(result))
    End Function

    Public Overridable Function keycount(ByVal result As pointer(Of Int64)) As eventComb _
                                        Implements islice.keycount
        Return workon(Function() slice.keycount(result))
    End Function

    Public Overridable Function list(ByVal result As pointer(Of vector(Of String))) As eventComb _
                                    Implements islice.list
        Return workon(Function() slice.list(result))
    End Function

    Public Overridable Function modify(ByVal key As String,
                                       ByVal buff As bytes,
                                       ByVal ts As Int64,
                                       ByVal result As pointer(Of Boolean)) As eventComb _
                                      Implements islice.modify
        Return workon(Function() slice.modify(key, buff, ts, result))
    End Function

    Public Overridable Function read(ByVal key As String,
                                     ByVal result As pointer(Of bytes),
                                     ByVal ts As pointer(Of Int64)) As eventComb _
                                    Implements islice.read
        Return workon(Function() slice.read(key, result, ts))
    End Function

    Public Overridable Function retire(ByVal result As pointer(Of Boolean)) As eventComb _
                                      Implements islice.retire
        Return workon(Function() slice.retire(result))
    End Function

    Public Overridable Function seek(ByVal key As String,
                                     ByVal result As pointer(Of Boolean)) As eventComb _
                                    Implements islice.seek
        Return workon(Function() slice.seek(key, result))
    End Function

    Public Overridable Function sizeof(ByVal key As String,
                                       ByVal result As pointer(Of Int64)) As eventComb _
                                      Implements islice.sizeof
        Return workon(Function() slice.sizeof(key, result))
    End Function

    Public Overridable Sub [stop]() Implements islice.stop
        slice.stop()
    End Sub

    Public Overridable Function uniqueWrite(ByVal key As String,
                                            ByVal buff As bytes,
                                            ByVal ts As Int64,
                                            ByVal result As pointer(Of Boolean)) As eventComb _
                                           Implements islice.uniqueWrite
        Return workon(Function() slice.uniqueWrite(key, buff, ts, result))
    End Function

    Public Overridable Function valuesize(ByVal result As pointer(Of Int64)) As eventComb _
                                         Implements islice.valuesize
        Return workon(Function() slice.valuesize(result))
    End Function

    Public Overridable Function write(ByVal key As String,
                                      ByVal buff As bytes,
                                      ByVal ts As Int64,
                                      ByVal result As pointer(Of Boolean)) As eventComb _
                                     Implements islice.write
        Return workon(Function() slice.write(key, buff, ts, result))
    End Function
End Class
